from moviepy.video.io.VideoFileClip import VideoFileClip
import pandas as pd


def trim_video(input_path, output_path, start_time, end_time):
    video_clip = VideoFileClip(input_path).subclip(start_time, end_time)
    video_clip.write_videofile(output_path, codec="libx264")


if __name__ == '__main__':
    input_video_path = "C:\\Users\\asus\\Downloads\\oceans.mp4"
    out_file_path = "C:\\Users\\asus\\Desktop\\709\\file"
    data = pd.read_excel('C:\\Users\\asus\\Desktop\\video_time.xlsx', sheet_name='Sheet1',
                         usecols=['文件名字', '开始时间', '结束时间'])
    for index, row in data.iterrows():
        outFileName = row['文件名字']

        output_video_path = out_file_path + '\\' + str(outFileName) + '.mp4'
        start = row['开始时间']
        end = row['结束时间']
        trim_video(input_video_path, output_video_path, start, end)
